package miage.rest.resource;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import java.util.List;
import miage.rest.xml.XstreamRepresentation;
import org.restlet.representation.Representation;

/**
 *
 * @author marya
 */
@XStreamAlias("error")
public class ResourceError {

    @XStreamAlias("message")
    @XStreamAsAttribute
    private String libelle;
    
    public ResourceError(String libelle) {
        this.libelle = libelle;
    }

    public String getLibelle() {
        return libelle;
    }

    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }

	public static Representation getNewRepresentation(ResourceError error) {
		return new XstreamRepresentation<ResourceError>(error);
	}

	public static Representation getNewRepresentation(List<ResourceError> errors) {
		XstreamRepresentation representation = new XstreamRepresentation<List<ResourceError>>(errors);
		XStream xstream = representation.getXstream();
		xstream.alias("errors", List.class, errors.getClass());
		xstream.processAnnotations(ResourceError.class);

		return representation;
	}

	public static Representation getNewRepresentation(String errorMessage) {
		return getNewRepresentation(new ResourceError(errorMessage));
	}

}
